<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Validators for Zend_File_Transfer - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.file.transfer.validators.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.file.transfer.validators.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.file.transfer.introduction.html">Zend_File_Transfer</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.file.html">Zend_File</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.file.transfer.filters.html">Filters for Zend_File_Transfer</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.file.transfer.validators" class="section"><div class="info"><h1 class="title">Validators for Zend_File_Transfer</h1></div>
    

    <p class="para">
        <span class="classname">Zend_File_Transfer</span> is delivered with several file-related validators
        which can be used to increase security and prevent possible attacks. Note that these
        validators are only as effective as how effectively you apply them. All validators provided
        with <span class="classname">Zend_File_Transfer</span> can be found in the
        <span class="classname">Zend_Validator</span> component and are named
        <span class="classname">Zend_Validate_File_*</span>. The following validators are available:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                <span class="classname">Count</span>: This validator checks for the number of files. A
                minimum and maximum range can be specified. An error will be thrown if either limit
                is crossed.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Crc32</span>: This validator checks for the crc32 hash value of the
                content from a file. It is based on the <span class="classname">Hash</span> validator and
                provides a convenient and simple validator that only supports Crc32.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">ExcludeExtension</span>: This validator checks the extension of
                files. It will throw an error when an given file has a defined extension. With this
                validator, you can exclude defined extensions from being validated.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">ExcludeMimeType</span>: This validator validates the
                <acronym class="acronym">MIME</acronym> type of files. It can also validate <acronym class="acronym">MIME</acronym>
                types and will throw an error if the <acronym class="acronym">MIME</acronym> type of specified file
                matches.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Exists</span>: This validator checks for the existence of files. It
                will throw an error when a specified file does not exist.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Extension</span>: This validator checks the extension of files. It
                will throw an error when a specified file has an undefined extension.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">FilesSize</span>: This validator checks the size of validated files.
                It remembers internally the size of all checked files and throws an error when the
                sum of all specified files exceed the defined size. It also provides minimum and
                maximum values.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">ImageSize</span>: This validator checks the size of image. It
                validates the width and height and enforces minimum and maximum dimensions.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">IsCompressed</span>: This validator checks whether the file is
                compressed. It is based on the <span class="classname">MimeType</span> validator and
                validates for compression archives like zip or arc. You can also limit it to other
                archives.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">IsImage</span>: This validator checks whether the file is an image.
                It is based on the <span class="classname">MimeType</span> validator and validates for image
                files like jpg or gif. You can also limit it to other image types.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Hash</span>: This validator checks the hash value of the content
                from a file. It supports multiple algorithms.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Md5</span>: This validator checks for the md5 hash value of the
                content from a file. It is based on the <span class="classname">Hash</span> validator and
                provides a convenient and simple validator that only supports Md5.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">MimeType</span>: This validator validates the
                <acronym class="acronym">MIME</acronym> type of files. It can also validate <acronym class="acronym">MIME</acronym>
                types and will throw an error if the <acronym class="acronym">MIME</acronym> type of a specified
                file does not match.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">NotExists</span>: This validator checks for the existence of files.
                It will throw an error when an given file does exist.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Sha1</span>: This validator checks for the sha1 hash value of the
                content from a file. It is based on the <span class="classname">Hash</span> validator and
                provides a convenient and simple validator that only supports sha1.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Size</span>: This validator is able to check files for its file
                size. It provides a minimum and maximum size range and will throw an error when
                either of these thesholds are crossed.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">Upload</span>: This validator is internal. It checks if an upload
                has resulted in an error. You must not set it, as it&#039;s automatically set by
                <span class="classname">Zend_File_Transfer</span> itself. So you do not use this validator
                directly. You should only know that it exists.
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="classname">WordCount</span>: This validator is able to check the number of
                words within files. It provides a minimum and maximum count and will throw an error
                when either of these thresholds are crossed.
            </p>
        </li>
    </ul>

    <div class="section" id="zend.file.transfer.validators.usage"><div class="info"><h1 class="title">Using Validators with Zend_File_Transfer</h1></div>
        

        <p class="para">
            Putting validators to work is quite simple. There are several methods for adding and
            manipulating validators:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                     <span class="methodname">isValid($files = null)</span>: Checks the specified files
                    using all validators. <var class="varname">$files</var> may be either a real filename,
                    the element&#039;s name or the name of the temporary file.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">addValidator($validator, $breakChainOnFailure, $options = null,
                        $files = null)</span>: Adds the specified validator to the validator
                    stack (optionally only to the file(s) specified).
                    <var class="varname">$validator</var> may be either an actual validator
                    instance or a short name specifying the validator type (e.g., &#039;Count&#039;).
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">addValidators(array $validators, $files =
                        null)</span>: Adds the specified validators to the stack of
                    validators. Each entry may be either a validator
                    type/options pair or an array with the key &#039;validator&#039;
                    specifying the validator. All other options will be
                    considered validator options for instantiation.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">setValidators(array $validators, $files =
                        null)</span>: Overwrites any existing validators with
                    the validators specified. The validators should follow the
                    syntax for  <span class="methodname">addValidators()</span>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">hasValidator($name)</span>: Indicates whether a
                    validator has been registered.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getValidator($name)</span>: Returns a previously
                    registered validator.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">getValidators($files = null)</span>: Returns
                    registered validators. If <var class="varname">$files</var> is specified,
                    returns validators for that particular file or set of
                    files.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">removeValidator($name)</span>: Removes a previously
                    registered validator.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                     <span class="methodname">clearValidators()</span>: Clears all
                    registered validators.
                </p>
            </li>
        </ul>

        <div class="example" id="zend.file.transfer.validators.usage.example"><div class="info"><p><b>Example #1 Add Validators to a File Transfer Object</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Set a file size with 20000 bytes
$upload-&gt;addValidator(&#039;Size&#039;, false, 20000);

// Set a file size with 20 bytes minimum and 20000 bytes maximum
$upload-&gt;addValidator(&#039;Size&#039;, false, array(&#039;min&#039; =&gt; 20, &#039;max&#039; =&gt; 20000));

// Set a file size with 20 bytes minimum and 20000 bytes maximum and
// a file count in one step
$upload-&gt;setValidators(array(
    &#039;Size&#039;  =&gt; array(&#039;min&#039; =&gt; 20, &#039;max&#039; =&gt; 20000),
    &#039;Count&#039; =&gt; array(&#039;min&#039; =&gt; 1, &#039;max&#039; =&gt; 3),
));
</pre>

        </div>

        <div class="example" id="zend.file.transfer.validators.usage.exampletwo"><div class="info"><p><b>Example #2 Limit Validators to Single Files</b></p></div>
            

            <div class="example-contents"><p>
                 <span class="methodname">addValidator()</span>,  <span class="methodname">addValidators()</span>,
                and  <span class="methodname">setValidators()</span> each accept a final
                <var class="varname">$files</var> argument. This argument can be used to
                specify a particular file or array of files on which to set the
                given validator.
            </p></div>

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Set a file size with 20000 bytes and limits it only to &#039;file2&#039;
$upload-&gt;addValidator(&#039;Size&#039;, false, 20000, &#039;file2&#039;);
</pre>

        </div>

        <p class="para">
            Normally, you should use the  <span class="methodname">addValidators()</span> method, which
            can be called multiple times.
        </p>

        <div class="example" id="zend.file.transfer.validators.usage.examplemultiple"><div class="info"><p><b>Example #3 Add Multiple Validators</b></p></div>
            

            <div class="example-contents"><p>
                Often it&#039;s simpler just to call  <span class="methodname">addValidator()</span> multiple
                times with one call for each validator. This also increases readability and makes
                your code more maintainable. All methods provide a fluent interface, so you can
                couple the calls as shown below:
            </p></div>

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Set a file size with 20000 bytes
$upload-&gt;addValidator(&#039;Size&#039;, false, 20000)
       -&gt;addValidator(&#039;Count&#039;, false, 2)
       -&gt;addValidator(&#039;Filessize&#039;, false, 25000);
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that setting the same validator
                multiple times is allowed, but doing so can lead to issues when using
                different options for the same validator.
            </p>
        </p></blockquote>

        <p class="para">
            Last but not least, you can simply check the files using
             <span class="methodname">isValid()</span>.
        </p>

        <div class="example" id="zend.file.transfer.validators.usage.exampleisvalid"><div class="info"><p><b>Example #4 Validate the Files</b></p></div>
            

            <div class="example-contents"><p>
                 <span class="methodname">isValid()</span> accepts the file name of the uploaded or
                downloaded file, the temporary file name and or the name of the form element. If
                no parameter or null is given all files will be validated
            </p></div>

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Set a file size with 20000 bytes
$upload-&gt;addValidator(&#039;Size&#039;, false, 20000)
       -&gt;addValidator(&#039;Count&#039;, false, 2)
       -&gt;addValidator(&#039;Filessize&#039;, false, 25000);

if ($upload-&gt;isValid()) {
    print &quot;Validation failure&quot;;
}
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that  <span class="methodname">isValid()</span> will be called automatically when you
                receive the files and have not called it previously.
            </p>
        </p></blockquote>

        <p class="para">
            When validation has failed it is a good idea to get information about the
            problems found. To get this information, you can use the methods
             <span class="methodname">getMessages()</span> which returns all validation messages as array,
             <span class="methodname">getErrors()</span> which returns all error codes, and
             <span class="methodname">hasErrors()</span> which returns <b><tt>TRUE</tt></b> as soon as
            a validation error has been found.
        </p>
    </div>

    <div class="section" id="zend.file.transfer.validators.count"><div class="info"><h1 class="title">Count Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Count</span> validator checks for the number of files which are
            provided. It supports the following option keys:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">min</span>: Sets the minimum number of files to transfer.
                </p>

                <blockquote class="note"><p><b class="note">Note</b>: 
                    <p class="para">
                        When using this option you must give the minimum number of files when
                        calling this validator the first time; otherwise you will get an error in
                        return.
                    </p>
                </p></blockquote>

                <p class="para">
                    With this option you can define the minimum number of files you expect to
                    receive.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">max</span>: Sets the maximum number of files to transfer.
                </p>

                <p class="para">
                    With this option you can limit the number of files which are accepted but also
                    detect a possible attack when more files are given than defined in your form.
                </p>
            </li>
        </ul>

        <p class="para">
            If you initiate this validator with a string or integer, the value will be used as
            <span class="property">max</span>. Or you can also use the methods
             <span class="methodname">setMin()</span> and  <span class="methodname">setMax()</span> to set both
            options afterwards and  <span class="methodname">getMin()</span> and
             <span class="methodname">getMax()</span> to retrieve the actual set values.
        </p>

        <div class="example" id="zend.file.transfer.validators.count.example"><div class="info"><p><b>Example #5 Using the Count Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Limit the amount of files to maximum 2
$upload-&gt;addValidator(&#039;Count&#039;, false, 2);

// Limit the amount of files to maximum 5 and minimum 1 file
$upload-&gt;addValidator(&#039;Count&#039;, false, array(&#039;min&#039; =&gt;1, &#039;max&#039; =&gt; 5));
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that this validator stores the number of checked files internally. The file
                which exceeds the maximum will be returned as error.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.crc32"><div class="info"><h1 class="title">Crc32 Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Crc32</span> validator checks the content of a transferred file by
            hashing it. This validator uses the hash extension from <acronym class="acronym">PHP</acronym> with the
            crc32 algorithm. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Sets any key or use a numeric array. The values will be
                    used as hash to validate against.
                </p>

                <p class="para">
                    You can set multiple hashes by using different keys. Each will be checked and
                    the validation will fail only if all values fail.
                </p>
            </li>
        </ul>

        <div class="example" id="zend.file.transfer.validators.crc32.example"><div class="info"><p><b>Example #6 Using the Crc32 Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Checks whether the content of the uploaded file has the given hash
$upload-&gt;addValidator(&#039;Crc32&#039;, false, &#039;3b3652f&#039;);

// Limits this validator to two different hashes
$upload-&gt;addValidator(&#039;Crc32&#039;, false, array(&#039;3b3652f&#039;, &#039;e612b69&#039;));
</pre>

        </div>
    </div>

    <div class="section" id="zend.file.transfer.validators.excludeextension"><div class="info"><h1 class="title">ExcludeExtension Validator</h1></div>
        

        <p class="para">
            The <span class="classname">ExcludeExtension</span> validator checks the file extension of the
            specified files. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Sets any key or use a numeric array. The values will be
                    used to check whether the given file does not use this file extension.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">case</span>: Sets a boolean indicating whether validation should
                    be case-sensitive. The default is not case sensitive. Note that this key can be
                    applied to for all available extensions.
                </p>
            </li>
        </ul>

        <p class="para">
            This validator accepts multiple extensions, either as a comma-delimited string, or as
            an array. You may also use the methods  <span class="methodname">setExtension()</span>,
             <span class="methodname">addExtension()</span>, and  <span class="methodname">getExtension()</span>
            to set and retrieve extensions.
        </p>

        <p class="para">
            In some cases it is useful to match in a case-sensitive fashion. So the constructor
            allows a second parameter called <var class="varname">$case</var> which, if set to
            <b><tt>TRUE</tt></b>, validates the extension by comparing it with the specified
            values in a case-sensitive fashion.
        </p>

        <div class="example" id="zend.file.transfer.validators.excludeextension.example"><div class="info"><p><b>Example #7 Using the ExcludeExtension Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Do not allow files with extension php or exe
$upload-&gt;addValidator(&#039;ExcludeExtension&#039;, false, &#039;php,exe&#039;);

// Do not allow files with extension php or exe, but use array notation
$upload-&gt;addValidator(&#039;ExcludeExtension&#039;, false, array(&#039;php&#039;, &#039;exe&#039;));

// Check in a case-sensitive fashion
$upload-&gt;addValidator(&#039;ExcludeExtension&#039;,
                      false,
                      array(&#039;php&#039;, &#039;exe&#039;, &#039;case&#039; =&gt; true));
$upload-&gt;addValidator(&#039;ExcludeExtension&#039;,
                      false,
                      array(&#039;php&#039;, &#039;exe&#039;, &#039;case&#039; =&gt; true));
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that this validator only checks the file extension. It does not check the
                file&#039;s <acronym class="acronym">MIME</acronym> type.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.excludemimetype"><div class="info"><h1 class="title">ExcludeMimeType Validator</h1></div>
        

        <p class="para">
            The <span class="classname">ExcludeMimeType</span> validator checks the <acronym class="acronym">MIME</acronym>
            type of transferred files. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Sets any key individually or use a numeric array. Sets
                    the <acronym class="acronym">MIME</acronym> type to validate against.
                </p>

                <p class="para">
                    With this option you can define the <acronym class="acronym">MIME</acronym> type of files that
                    are not to be accepted.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">headerCheck</span>: If set to <b><tt>TRUE</tt></b> this
                    option will check the <acronym class="acronym">HTTP</acronym> Information for the file type when
                    the <em class="emphasis">fileInfo</em> or <em class="emphasis">mimeMagic</em> extensions
                    can not be found. The default value for this option is
                    <b><tt>FALSE</tt></b>.
                </p>
            </li>
        </ul>

        <p class="para">
            This validator accepts multiple <acronym class="acronym">MIME</acronym> types, either as a
            comma-delimited string, or as an array. You may also use the methods
             <span class="methodname">setMimeType()</span>,  <span class="methodname">addMimeType()</span>, and
             <span class="methodname">getMimeType()</span> to set and retrieve the <acronym class="acronym">MIME</acronym>
            types.
        </p>

        <div class="example" id="zend.file.transfer.validators.excludemimetype.example"><div class="info"><p><b>Example #8 Using the ExcludeMimeType Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Does not allow MIME type of gif images for all files
$upload-&gt;addValidator(&#039;ExcludeMimeType&#039;, false, &#039;image/gif&#039;);

// Does not allow MIME type of gif and jpg images for all given files
$upload-&gt;addValidator(&#039;ExcludeMimeType&#039;, false, array(&#039;image/gif&#039;,
                                                      &#039;image/jpeg&#039;);

// Does not allow MIME type of the group images for all given files
$upload-&gt;addValidator(&#039;ExcludeMimeType&#039;, false, &#039;image&#039;);
</pre>

        </div>

        <p class="para">
            The above example shows that it is also possible to disallow groups of
            <acronym class="acronym">MIME</acronym> types. For example, to disallow all images, just use &#039;image&#039; as
            the <acronym class="acronym">MIME</acronym> type. This can be used for all groups of
            <acronym class="acronym">MIME</acronym> types like &#039;image&#039;, &#039;audio&#039;, &#039;video&#039;, &#039;text&#039;, etc.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that disallowing groups of <acronym class="acronym">MIME</acronym> types will disallow all
                members of this group even if this is not intentional. When you disallow &#039;image&#039; you
                will disallow all types of images like &#039;image/jpeg&#039; or &#039;image/vasa&#039;. When you are
                not sure if you want to disallow all types, you should disallow only specific
                <acronym class="acronym">MIME</acronym> types instead of complete groups.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.exists"><div class="info"><h1 class="title">Exists Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Exists</span> validator checks for the existence of specified
            files. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Sets any key or use a numeric array to check if the
                    specific file exists in the given directory.
                </p>
            </li>
        </ul>

        <p class="para">
            This validator accepts multiple directories, either as a comma-delimited string, or as
            an array. You may also use the methods  <span class="methodname">setDirectory()</span>,
             <span class="methodname">addDirectory()</span>, and  <span class="methodname">getDirectory()</span>
            to set and retrieve directories.
        </p>

        <div class="example" id="zend.file.transfer.validators.exists.example"><div class="info"><p><b>Example #9 Using the Exists Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Add the temp directory to check for
$upload-&gt;addValidator(&#039;Exists&#039;, false, &#039;\temp&#039;);

// Add two directories using the array notation
$upload-&gt;addValidator(&#039;Exists&#039;,
                      false,
                      array(&#039;\home\images&#039;, &#039;\home\uploads&#039;));
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that this validator checks whether the specified file exists in all of the
                given directories. The validation will fail if the file does not exist in any of the
                given directories.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.extension"><div class="info"><h1 class="title">Extension Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Extension</span> validator checks the file extension of the
            specified files. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Sets any key or use a numeric array to check whether the
                    specified file has this file extension.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">case</span>: Sets whether validation should be done in a
                    case-sensitive fashion. The default is no case sensitivity. Note the this key is
                    used for all given extensions.
                </p>
            </li>
        </ul>

        <p class="para">
            This validator accepts multiple extensions, either as a comma-delimited string, or as an
            array. You may also use the methods  <span class="methodname">setExtension()</span>,
             <span class="methodname">addExtension()</span>, and  <span class="methodname">getExtension()</span> to
            set and retrieve extension values.
        </p>

        <p class="para">
            In some cases it is useful to test in a case-sensitive fashion. Therefore the
            constructor takes a second parameter <var class="varname">$case</var>, which, if set to
            <b><tt>TRUE</tt></b>, will validate the extension in a case-sensitive fashion.
        </p>

        <div class="example" id="zend.file.transfer.validators.extension.example"><div class="info"><p><b>Example #10 Using the Extension Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Limit the extensions to jpg and png files
$upload-&gt;addValidator(&#039;Extension&#039;, false, &#039;jpg,png&#039;);

// Limit the extensions to jpg and png files but use array notation
$upload-&gt;addValidator(&#039;Extension&#039;, false, array(&#039;jpg&#039;, &#039;png&#039;));

// Check case sensitive
$upload-&gt;addValidator(&#039;Extension&#039;, false, array(&#039;mo&#039;, &#039;png&#039;, &#039;case&#039; =&gt; true));
if (!$upload-&gt;isValid(&#039;C:\temp\myfile.MO&#039;)) {
    print &#039;Not valid because MO and mo do not match with case sensitivity;
}
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that this validator only checks the file extension. It does not check the
                file&#039;s <acronym class="acronym">MIME</acronym> type.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.filessize"><div class="info"><h1 class="title">FilesSize Validator</h1></div>
        

        <p class="para">
            The <span class="classname">FilesSize</span> validator checks for the aggregate size of all
            transferred files. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">min</span>: Sets the minimum aggregate file size.
                    This option defines the minimum aggregate file size to be transferred.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">max</span>: Sets the maximum aggregate file size.
                </p>

                <p class="para">
                    This option limits the aggregate file size of all transferred files, but not the
                    file size of individual files.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">bytestring</span>: Defines whether a failure is to return a
                    user-friendly number or the plain file size.
                </p>

                <p class="para">
                    This option defines whether the user sees &#039;10864&#039; or &#039;10MB&#039;. The default value
                    is <b><tt>TRUE</tt></b>, so &#039;10MB&#039; is returned if you did not specify
                    otherwise.
                </p>
            </li>
        </ul>

        <p class="para">
            You can initialize this validator with a string, which will then be used to set the
            <span class="property">max</span> option. You can also use the methods
             <span class="methodname">setMin()</span> and  <span class="methodname">setMax()</span> to set both
            options after construction, along with  <span class="methodname">getMin()</span> and
             <span class="methodname">getMax()</span> to retrieve the values that have been set previously.
        </p>

        <p class="para">
            The size itself is also accepted in SI notation as handled by most operating systems.
            That is, instead of specifying <em class="emphasis">20000 bytes</em>,
            <em class="emphasis">20kB</em> may be given. All file sizes are converted using 1024 as the
            base value. The following Units are accepted: <em class="emphasis">kB</em>,
            <em class="emphasis">MB</em>, <em class="emphasis">GB</em>, <em class="emphasis">TB</em>,
            <em class="emphasis">PB</em> and <em class="emphasis">EB</em>. Note that 1kB is equal to 1024
            bytes, 1MB is equal to 1024kB, and so on.
        </p>

        <div class="example" id="zend.file.transfer.validators.filessize.example"><div class="info"><p><b>Example #11 Using the FilesSize Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Limit the size of all files to be uploaded to 40000 bytes
$upload-&gt;addValidator(&#039;FilesSize&#039;, false, 40000);

// Limit the size of all files to be uploaded to maximum 4MB and mimimum 10kB
$upload-&gt;addValidator(&#039;FilesSize&#039;,
                      false,
                      array(&#039;min&#039; =&gt; &#039;10kB&#039;, &#039;max&#039; =&gt; &#039;4MB&#039;));

// As before, but returns the plain file size instead of a user-friendly string
$upload-&gt;addValidator(&#039;FilesSize&#039;,
                      false,
                      array(&#039;min&#039; =&gt; &#039;10kB&#039;,
                            &#039;max&#039; =&gt; &#039;4MB&#039;,
                            &#039;bytestring&#039; =&gt; false));
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that this validator internally stores the file size of checked files. The file
                which exceeds the size will be returned as an error.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.imagesize"><div class="info"><h1 class="title">ImageSize Validator</h1></div>
        

        <p class="para">
            The <span class="classname">ImageSize</span> validator checks the size of image files.
            It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">minheight</span>: Sets the minimum image height.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">maxheight</span>: Sets the maximum image height.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">minwidth</span>: Sets the minimum image width.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">maxwidth</span>: Sets the maximum image width.
                </p>
            </li>
        </ul>

        <p class="para">
            The methods  <span class="methodname">setImageMin()</span> and
             <span class="methodname">setImageMax()</span> also set both minimum and maximum values, while
            the methods  <span class="methodname">getMin()</span> and  <span class="methodname">getMax()</span>
            return the currently set values.
        </p>

        <p class="para">
            For your convenience there are also the  <span class="methodname">setImageWidth()</span> and
             <span class="methodname">setImageHeight()</span> methods, which set the minimum and maximum
            height and width of the image file. They, too, have corresponding
             <span class="methodname">getImageWidth()</span> and  <span class="methodname">getImageHeight()</span>
            methods to retrieve the currently set values.
        </p>

        <p class="para">
            To bypass validation of a particular dimension, the relevent option simply should not be
            set.
        </p>

        <div class="example" id="zend.file.transfer.validators.imagesize.example"><div class="info"><p><b>Example #12 Using the ImageSize Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Limit the size of a image to a height of 100-200 and a width of
// 40-80 pixel
$upload-&gt;addValidator(&#039;ImageSize&#039;, false,
                      array(&#039;minwidth&#039; =&gt; 40,
                            &#039;maxwidth&#039; =&gt; 80,
                            &#039;minheight&#039; =&gt; 100,
                            &#039;maxheight&#039; =&gt; 200)
                      );

// Reset the width for validation
$upload-&gt;setImageWidth(array(&#039;minwidth&#039; =&gt; 20, &#039;maxwidth&#039; =&gt; 200));
</pre>

        </div>
    </div>

    <div class="section" id="zend.file.transfer.validators.iscompressed"><div class="info"><h1 class="title">IsCompressed Validator</h1></div>
        

        <p class="para">
            The <span class="classname">IsCompressed</span> validator checks if a transferred file is a
            compressed archive, such as zip or arc. This validator is based on the
            <span class="classname">MimeType</span> validator and supports the same methods and options.
            You may also limit this validator to particular compression types with the methods
            described there.
        </p>

        <div class="example" id="zend.file.transfer.validators.iscompressed.example"><div class="info"><p><b>Example #13 Using the IsCompressed Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Checks is the uploaded file is a compressed archive
$upload-&gt;addValidator(&#039;IsCompressed&#039;, false);

// Limits this validator to zip files only
$upload-&gt;addValidator(&#039;IsCompressed&#039;, false, array(&#039;application/zip&#039;));

// Limits this validator to zip files only using simpler notation
$upload-&gt;addValidator(&#039;IsCompressed&#039;, false, &#039;zip&#039;);
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that there is no check if you set a <acronym class="acronym">MIME</acronym> type that is not a
                archive. For example, it would be possible to define gif files to be accepted by
                this validator. Using the &#039;MimeType&#039; validator for files which are not archived will
                result in more readable code.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.isimage"><div class="info"><h1 class="title">IsImage Validator</h1></div>
        

        <p class="para">
            The <span class="classname">IsImage</span> validator checks if a transferred file is a image
            file, such as gif or jpeg. This validator is based on the
            <span class="classname">MimeType</span> validator and supports the same methods and options.
            You can limit this validator to particular image types with the methods described there.
        </p>

        <div class="example" id="zend.file.transfer.validators.isimage.example"><div class="info"><p><b>Example #14 Using the IsImage Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Checks whether the uploaded file is a image file
$upload-&gt;addValidator(&#039;IsImage&#039;, false);

// Limits this validator to gif files only
$upload-&gt;addValidator(&#039;IsImage&#039;, false, array(&#039;application/gif&#039;));

// Limits this validator to jpeg files only using a simpler notation
$upload-&gt;addValidator(&#039;IsImage&#039;, false, &#039;jpeg&#039;);
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that there is no check if you set a <acronym class="acronym">MIME</acronym> type that is not an
                image. For example, it would be possible to define zip files to be accepted by this
                validator. Using the &#039;MimeType&#039; validator for files which are not images will result
                in more readable code.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.hash"><div class="info"><h1 class="title">Hash Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Hash</span> validator checks the content of a transferred file by
            hashing it. This validator uses the hash extension from <acronym class="acronym">PHP</acronym>. It
            supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Takes any key or use a numeric array. Sets the hash to
                    validate against.
                </p>

                <p class="para">
                    You can set multiple hashes by passing them as an array. Each file is checked,
                    and the validation will fail only if all files fail validation.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">algorithm</span>: Sets the algorithm to use for hashing the
                    content.
                </p>

                <p class="para">
                    You can set multiple algorithm by calling the  <span class="methodname">addHash()</span>
                    method multiple times.
                </p>
            </li>
        </ul>

        <div class="example" id="zend.file.transfer.validators.hash.example"><div class="info"><p><b>Example #15 Using the Hash Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Checks if the content of the uploaded file contains the given hash
$upload-&gt;addValidator(&#039;Hash&#039;, false, &#039;3b3652f&#039;);

// Limits this validator to two different hashes
$upload-&gt;addValidator(&#039;Hash&#039;, false, array(&#039;3b3652f&#039;, &#039;e612b69&#039;));

// Sets a different algorithm to check against
$upload-&gt;addValidator(&#039;Hash&#039;,
                      false,
                      array(&#039;315b3cd8273d44912a7&#039;,
                            &#039;algorithm&#039; =&gt; &#039;md5&#039;));
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                This validator supports about 34 different hash algorithms. The most common include
                &#039;crc32&#039;, &#039;md5&#039; and &#039;sha1&#039;. A comprehesive list of supports hash algorithms can be
                found at the <a href="http://php.net/hash_algos" class="link external">&raquo; hash_algos method</a> on the
                <a href="http://php.net" class="link external">&raquo; php.net site</a>.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.md5"><div class="info"><h1 class="title">Md5 Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Md5</span> validator checks the content of a transferred file by
            hashing it. This validator uses the hash extension for <acronym class="acronym">PHP</acronym> with the
            md5 algorithm. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Takes any key or use a numeric array.
                </p>

                <p class="para">
                    You can set multiple hashes by passing them as an array. Each file is checked,
                    and the validation will fail only if all files fail validation.
                </p>
            </li>
        </ul>

        <div class="example" id="zend.file.transfer.validators.md5.example"><div class="info"><p><b>Example #16 Using the Md5 Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Checks if the content of the uploaded file has the given hash
$upload-&gt;addValidator(&#039;Md5&#039;, false, &#039;3b3652f336522365223&#039;);

// Limits this validator to two different hashes
$upload-&gt;addValidator(&#039;Md5&#039;,
                      false,
                      array(&#039;3b3652f336522365223&#039;,
                            &#039;eb3365f3365ddc65365&#039;));
</pre>

        </div>
    </div>

    <div class="section" id="zend.file.transfer.validators.mimetype"><div class="info"><h1 class="title">MimeType Validator</h1></div>
        

        <p class="para">
            The <span class="classname">MimeType</span> validator checks the <acronym class="acronym">MIME</acronym> type of
            transferred files. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Sets any key or use a numeric array. Sets the
                    <acronym class="acronym">MIME</acronym> type to validate against.
                </p>

                <p class="para">
                    Defines the <acronym class="acronym">MIME</acronym> type of files to be accepted.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">headerCheck</span>: If set to <b><tt>TRUE</tt></b> this
                    option will check the <acronym class="acronym">HTTP</acronym> Information for the file type when
                    the <em class="emphasis">fileInfo</em> or <em class="emphasis">mimeMagic</em> extensions
                    can not be found. The default value for this option is
                    <b><tt>FALSE</tt></b>.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">magicfile</span>: The magicfile to be used.
                </p>

                <p class="para">
                    With this option you can define which magicfile to use. When it&#039;s not set or
                    empty, the MAGIC constant will be used instead. This option is available since
                    Zend Framework 1.7.1.
                </p>
            </li>
        </ul>

        <p class="para">
            This validator accepts multiple <acronym class="acronym">MIME</acronym> type, either as a
            comma-delimited string, or as an array. You may also use the methods
             <span class="methodname">setMimeType()</span>,  <span class="methodname">addMimeType()</span>, and
             <span class="methodname">getMimeType()</span> to set and retrieve <acronym class="acronym">MIME</acronym>
            type.
        </p>

        <p class="para">
            You can also set the magicfile which shall be used by fileinfo with the &#039;magicfile&#039;
            option. Additionally there are convenient  <span class="methodname">setMagicFile()</span> and
             <span class="methodname">getMagicFile()</span> methods which allow later setting and retrieving
            of the magicfile parameter. This methods are available since Zend Framework 1.7.1.
        </p>

        <div class="example" id="zend.file.transfer.validators.mimetype.example"><div class="info"><p><b>Example #17 Using the MimeType Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Limit the MIME type of all given files to gif images
$upload-&gt;addValidator(&#039;MimeType&#039;, false, &#039;image/gif&#039;);

// Limit the MIME type of all given files to gif and jpeg images
$upload-&gt;addValidator(&#039;MimeType&#039;, false, array(&#039;image/gif&#039;, &#039;image/jpeg&#039;);

// Limit the MIME type of all given files to the group images
$upload-&gt;addValidator(&#039;MimeType&#039;, false, &#039;image&#039;);

// Use a different magicfile
$upload-&gt;addValidator(&#039;MimeType&#039;,
                      false,
                      array(&#039;image&#039;,
                            &#039;magicfile&#039; =&gt; &#039;/path/to/magicfile.mgx&#039;));
</pre>

        </div>

        <p class="para">
            The above example shows that it is also possible to limit the accepted
            <acronym class="acronym">MIME</acronym> type to a group of <acronym class="acronym">MIME</acronym> types. To allow all
            images just use &#039;image&#039; as <acronym class="acronym">MIME</acronym> type. This can be used for all groups
            of <acronym class="acronym">MIME</acronym> types like &#039;image&#039;, &#039;audio&#039;, &#039;video&#039;, &#039;text, and so on.
        </p>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that allowing groups of <acronym class="acronym">MIME</acronym> types will accept all members
                of this group even if your application does not support them. When you allow &#039;image&#039;
                you will also get &#039;image/xpixmap&#039; or &#039;image/vasa&#039; which could be problematic. When
                you are not sure if your application supports all types you should better allow only
                defined <acronym class="acronym">MIME</acronym> types instead of the complete group.
            </p>
        </p></blockquote>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                This component will use the <span class="classname">FileInfo</span> extension if it is
                available. If it&#039;s not, it will degrade to the
                 <span class="methodname">mime_content_type()</span> function. And if the function call
                fails it will use the <acronym class="acronym">MIME</acronym> type which is given by
                <acronym class="acronym">HTTP</acronym>.
            </p>

            <p class="para">
                You should be aware of possible security problems when you have whether
                <span class="classname">FileInfo</span> nor  <span class="methodname">mime_content_type()</span>
                available. The <acronym class="acronym">MIME</acronym> type given by <acronym class="acronym">HTTP</acronym> is not
                secure and can be easily manipulated.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.notexists"><div class="info"><h1 class="title">NotExists Validator</h1></div>
        

        <p class="para">
            The <span class="classname">NotExists</span> validator checks for the existence of the provided
            files. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Set any key or use a numeric array. Checks whether the
                    file exists in the given directory.
                </p>
            </li>
        </ul>

        <p class="para">
            This validator accepts multiple directories either as a comma-delimited string, or as an
            array. You may also use the methods  <span class="methodname">setDirectory()</span>,
             <span class="methodname">addDirectory()</span>, and  <span class="methodname">getDirectory()</span> to
            set and retrieve directories.
        </p>

        <div class="example" id="zend.file.transfer.validators.notexists.example"><div class="info"><p><b>Example #18 Using the NotExists Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Add the temp directory to check
$upload-&gt;addValidator(&#039;NotExists&#039;, false, &#039;\temp&#039;);

// Add two directories using the array notation
$upload-&gt;addValidator(&#039;NotExists&#039;, false,
                      array(&#039;\home\images&#039;,
                            &#039;\home\uploads&#039;)
                     );
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: 
            <p class="para">
                Note that this validator checks if the file does not exist in all of the provided
                directories. The validation will fail if the file does exist in any of the given
                directories.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.file.transfer.validators.sha1"><div class="info"><h1 class="title">Sha1 Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Sha1</span> validator checks the content of a transferred file by
            hashing it. This validator uses the hash extension for <acronym class="acronym">PHP</acronym> with the
            sha1 algorithm. It supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">*</span>: Takes any key or use a numeric array.
                </p>

                <p class="para">
                    You can set multiple hashes by passing them as an array. Each file is checked,
                    and the validation will fail only if all files fail validation.
                </p>
            </li>
        </ul>

        <div class="example" id="zend.file.transfer.validators.sha1.example"><div class="info"><p><b>Example #19 Using the sha1 Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Checks if the content of the uploaded file has the given hash
$upload-&gt;addValidator(&#039;sha1&#039;, false, &#039;3b3652f336522365223&#039;);

// Limits this validator to two different hashes
$upload-&gt;addValidator(&#039;Sha1&#039;,
                      false, array(&#039;3b3652f336522365223&#039;,
                                   &#039;eb3365f3365ddc65365&#039;));
</pre>

        </div>
    </div>

    <div class="section" id="zend.file.transfer.validators.size"><div class="info"><h1 class="title">Size Validator</h1></div>
        

        <p class="para">
            The <span class="classname">Size</span> validator checks for the size of a single file. It
            supports the following options:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">min</span>: Sets the minimum file size.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">max</span>: Sets the maximum file size.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">bytestring</span>: Defines whether a failure is returned with a
                    user-friendly number, or with the plain file size.
                </p>

                <p class="para">
                    With this option you can define if the user gets &#039;10864&#039; or &#039;10MB&#039;. Default
                    value is <b><tt>TRUE</tt></b> which returns &#039;10MB&#039;.
                </p>
            </li>
        </ul>

        <p class="para">
            You can initialize this validator with a string, which will then be used to set the
            <span class="property">max</span> option. You can also use the methods
             <span class="methodname">setMin()</span> and  <span class="methodname">setMax()</span> to set both
            options after construction, along with  <span class="methodname">getMin()</span> and
             <span class="methodname">getMax()</span> to retrieve the values that have been set previously.
        </p>

        <p class="para">
            The size itself is also accepted in SI notation as handled by most operating systems.
            That is, instead of specifying <em class="emphasis">20000 bytes</em>,
            <em class="emphasis">20kB</em> may be given. All file sizes are converted using 1024 as the
            base value. The following Units are accepted: <em class="emphasis">kB</em>,
            <em class="emphasis">MB</em>, <em class="emphasis">GB</em>, <em class="emphasis">TB</em>,
            <em class="emphasis">PB</em> and <em class="emphasis">EB</em>. Note that 1kB is equal to 1024
            bytes, 1MB is equal to 1024kB, and so on.
        </p>

        <div class="example" id="zend.file.transfer.validators.size.example"><div class="info"><p><b>Example #20 Using the Size Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Limit the size of a file to 40000 bytes
$upload-&gt;addValidator(&#039;Size&#039;, false, 40000);

// Limit the size a given file to maximum 4MB and mimimum 10kB
// Also returns the plain number in case of an error
// instead of a user-friendly number
$upload-&gt;addValidator(&#039;Size&#039;,
                      false,
                      array(&#039;min&#039; =&gt; &#039;10kB&#039;,
                            &#039;max&#039; =&gt; &#039;4MB&#039;,
                            &#039;bytestring&#039; =&gt; false));
</pre>

        </div>
    </div>

    <div class="section" id="zend.file.transfer.validators.wordcount"><div class="info"><h1 class="title">WordCount Validator</h1></div>
        

        <p class="para">
            The <span class="classname">WordCount</span> validator checks for the number of words within
            provided files. It supports the following option keys:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <span class="property">min</span>: Sets the minimum number of words to be found.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <span class="property">max</span>: Sets the maximum number of words to be found.
                </p>
            </li>
        </ul>

        <p class="para">
            If you initiate this validator with a string or integer, the value will be used as
            <span class="property">max</span>. Or you can also use the methods
             <span class="methodname">setMin()</span> and  <span class="methodname">setMax()</span> to set both
            options afterwards and  <span class="methodname">getMin()</span> and
             <span class="methodname">getMax()</span> to retrieve the actual set values.
        </p>

        <div class="example" id="zend.file.transfer.validators.wordcount.example"><div class="info"><p><b>Example #21 Using the WordCount Validator</b></p></div>
            

            <pre class="programlisting brush: php">
$upload = new Zend_File_Transfer();

// Limit the amount of words within files to maximum 2000
$upload-&gt;addValidator(&#039;WordCount&#039;, false, 2000);

// Limit the amount of words within files to maximum 5000 and minimum 1000 words
$upload-&gt;addValidator(&#039;WordCount&#039;, false, array(&#039;min&#039; =&gt; 1000, &#039;max&#039; =&gt; 5000));
</pre>

        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.file.transfer.introduction.html">Zend_File_Transfer</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.file.html">Zend_File</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.file.transfer.filters.html">Filters for Zend_File_Transfer</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.file.html">Zend_File</a></li>
  <li><a href="zend.file.transfer.introduction.html">Zend_File_Transfer</a></li>
  <li class="active"><a href="zend.file.transfer.validators.html">Validators for Zend_File_Transfer</a></li>
  <li><a href="zend.file.transfer.filters.html">Filters for Zend_File_Transfer</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>